package my.jwds.p682;

import java.util.*;

public class CalPoints {
    public static void main(String[] args) {
        CalPoints obj = new CalPoints();
    }


    public int calPoints(String[] ops) {
        List<Integer> stack = new ArrayList<>();

        for (String str : ops) {

            if (str.equals("+")){
                stack.add(stack.get(stack.size() - 1) + stack.get(stack.size()-2));
            }else if (str.equals("D")){
                stack.add(stack.get(stack.size() -1)*2);
            }else if (str.equals("C")){
                stack.remove(stack.size()-1);
            }else{
                stack.add(Integer.valueOf(str));
            }

        }
        int res = 0;
        for (Integer integer : stack) {
            res+=integer;
        }
        return res;

    }
}